using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication11.Models.Mapping
{
    public class MsgDetailMap : EntityTypeConfiguration<MsgDetail>
    {
        public MsgDetailMap()
        {
            // Primary Key
            this.HasKey(t => t.SMSID);

            // Properties
            this.Property(t => t.ReceiverName)
                .HasMaxLength(50);

            this.Property(t => t.ReceiverID)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.MobileNumber)
                .HasMaxLength(30);

            this.Property(t => t.Content)
                .HasMaxLength(2000);

            // Table & Column Mappings
            this.ToTable("MsgDetails");
            this.Property(t => t.SMSID).HasColumnName("SMSID");
            this.Property(t => t.ServiceID).HasColumnName("ServiceID");
            this.Property(t => t.ReceiverName).HasColumnName("ReceiverName");
            this.Property(t => t.ReceiverID).HasColumnName("ReceiverID");
            this.Property(t => t.MobileNumber).HasColumnName("MobileNumber");
            this.Property(t => t.Content).HasColumnName("Content");
            this.Property(t => t.Cycle).HasColumnName("Cycle");
            this.Property(t => t.NextSendTime).HasColumnName("NextSendTime");
            this.Property(t => t.StartTime).HasColumnName("StartTime");
            this.Property(t => t.AvailableTime).HasColumnName("AvailableTime");
            this.Property(t => t.ServiceType).HasColumnName("ServiceType");
            this.Property(t => t.Status).HasColumnName("Status");

            // Relationships
            this.HasRequired(t => t.MsgService)
                .WithMany(t => t.MsgDetails)
                .HasForeignKey(d => d.ServiceID);

        }
    }
}
